import CodeView from '../../../shared/components/CodeView';
import CodeBlock from '../../../shared/components/CodeBlock';
import Example from '../../../shared/components/Example';
import Blockquote from '../../../shared/components/Blockquote';
import { AppLauncherModal, AppLauncherTile, appTiles, appTilesGrabbed, appTilesMoved, appTilesDropped, appTilesSearch, itemTiles, searchItemTiles } from './base/example'
import * as AppLauncherExamples from './base/example';
import { getDisplayElementById, getDemoStylesById } from '../../shared/helpers';

<div className="doc lead">
  The App Launcher allows the user to quickly access all the apps and functionality within their organization.
</div>

<CodeView isViewport exampleOnly demoStyles="height: 600px;">
  {getDisplayElementById(AppLauncherExamples.default)}
</CodeView>

## About App Launcher

The App Launcher is a [modal dialog](/components/modals) which contains 2 sections of information. The top section is a list of all the applications installed in the organization, and the second section is the list of items in that organization.

The 2 sections are implemented as [Expandable Sections](/components/expandable-section/) and can be expanded or collapsed. Applications and Items are also searchable within the modal via the search input in the modal header.

## Base

<CodeView isViewport demoStyles={getDemoStylesById(AppLauncherExamples.states, 'default')}>
  {getDisplayElementById(AppLauncherExamples.states, 'default')}
</CodeView>

## Description overflow

When the tile description is too long to fit on 2 lines, a "more" `button` is shown after an ellipsis. Text truncation isn't handled via CSS in the case of an App Launcher Tile due to the responsive nature of the tile size.

<Blockquote type="note" header="Truncate via JavaScript">
  <p>
    Multi-line truncation can only be done via JavaScript. You should calculate how many characters will fit over a maximum of 2 lines, depending on the tile width and trim the string accordingly.
  </p>
</Blockquote>

On hover or focus, the more `button` will display the full description using a [Tooltip](/components/tooltips)

<CodeView demoStyles={getDemoStylesById(AppLauncherExamples.states, 'tooltip')}>
  {getDisplayElementById(AppLauncherExamples.states, 'tooltip')}
</CodeView>

## Reordering tiles via drag and drop

App tiles can be re-ordered via mouse drag and drop or with the keyboard via the use of the grab handle button under the avatar. The grab handle button is implemented as a [Stateful Icon Button](/components/button-icons/#Stateful)

<Blockquote type="a11y" header="Communicating to assistive technology">
  <p>
    When implementing drag and drop it is important to be able to communicate what is happening visually on the screen to assistive technology users. We do this via an Assertive Live Region, which is placed before the list of tiles, and has <code>aria-live="assertive"</code>
  </p>
</Blockquote>

### Tile grabbed

When a tile is grabbed add the class name of `slds-is-grabbed` to the tile class list. When initiating the grab via the stateful button, be sure to set `aria-pressed="true"` on the button. Also be sure to update the contents of the live region to communicate what was grabbed, its current position and how to move the item. Something like: _"Sales Cloud: current position 1 of 6. Use the up and down arrows to move this app"_

<CodeView isViewport demoStyles={getDemoStylesById(AppLauncherExamples.states, 'grabbed')}>
  {getDisplayElementById(AppLauncherExamples.states, 'grabbed')}
</CodeView>

### Tile moved in list

When the tile is moved in the list using a keyboard, update the live region for every move to indicate its new position to the user. Something like: _"Sales Cloud: new position 3 of 6."_

<CodeView isViewport demoStyles={getDemoStylesById(AppLauncherExamples.states, 'moved')}>
  {getDisplayElementById(AppLauncherExamples.states, 'moved')}
</CodeView>

### Tile dropped

Finally, when a tile is dropped into its final position, reset `aria-pressed` to be `false` on the stateful button, and update the live region to inform the user of the items final position. e.g. _"Sales Cloud: final position 4 of 6."_

<CodeView isViewport demoStyles={getDemoStylesById(AppLauncherExamples.states, 'dropped')}>
  {getDisplayElementById(AppLauncherExamples.states, 'dropped')}
</CodeView>

## Searching

When using the search input at the top of the modal, the list of applications and items filters as the user types. The remaining items on display have the matching search term highlighted with the use of the `<mark />` element wrapping the matching term. This creates the visual highlight around the term.

<CodeView isViewport demoStyles={getDemoStylesById(AppLauncherExamples.states, 'search')}>
  {getDisplayElementById(AppLauncherExamples.states, 'search')}
</CodeView>
